const app = getApp()
const util = require('../../utils/util.js')
Page({
  data: {
    myuserinfo: {},
    rankinglist: {},
    widhts: '',
    heights: '',
    openid: ''
  },
  onLoad: function(options) {
    var that = this;
    wx.cloud.init()
    wx.cloud.callFunction({
      name: 'getUserInfo',
    }).then(
      res => {
        console.log(res.result.openId)
        that.setData({
          openid: res.result.openId
        })
      })
    // 生命周期函数--监听页面加载

    // 生命周期函数--监听页面显示
    that.setData({
      widhts: wx.getStorageSync('w'),
      heights: wx.getStorageSync('y')
    })
    wx.request({
      url: app.APIURL + 'getOpenidUser',
      type: 'get',
      data: {
        openId: that.data.openid
      },
      success: function(r) {
        console.log(r)
        that.setData({
          myuserinfo: r.data[0]
        })
      }
    })
    wx.request({
      url: app.APIURL + 'getUserListTop',
      type: 'get',
      success: function (r) {
        console.log(r)
        that.setData({
          rankinglist:r.data
        })
      }
    })

  },
  onReady: function() {
    // 生命周期函数--监听页面初次渲染完成

  },
  onShow: function() {},
  onHide: function() {
    // 生命周期函数--监听页面隐藏

  },
  onUnload: function() {
    // 生命周期函数--监听页面卸载

  },
  onPullDownRefresh: function() {
    // 页面相关事件处理函数--监听用户下拉动作

  },
  onReachBottom: function() {
    // 页面上拉触底事件的处理函数

  },
  onShareAppMessage: function() {
    // 用户点击右上角分享
    return {
      title: 'title', // 分享标题
      desc: 'desc', // 分享描述
      path: 'path' // 分享路径
    }
  }
})